﻿package plugin.wing.handler
{
    import com.core.*;
    import consts.*;
    import flash.utils.*;
    import plugin.wing.component.*;
    import pluginfw.nio.*;
    import pluginfw.nio.imsg.*;

    public class WingHandler extends Object implements IGroupHandler
    {

        public function WingHandler()
        {
            return;
        }// end function

        public function dealSimpleMessage(param1:ISimpleMessage) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Array = null;
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            var _loc_6:Boolean = false;
            var _loc_7:Object = null;
            var _loc_8:Object = null;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:Object = null;
            var _loc_12:Object = null;
            var _loc_13:Boolean = false;
            var _loc_14:int = 0;
            var _loc_15:Object = null;
            switch(param1.getCmd())
            {
                case CMDWing.Init:
                {
                    ModelProxy.change("wing", "init", param1.getParam());
                    ModelProxy.change("data", "wing", param1.getParam());
                    _loc_2 = param1.getParam();
                    ModelProxy.change("data", "wingLuck", _loc_2[0].luck);
                    ModelProxy.change("mainview", "showWingCount", null);
                    break;
                }
                case CMDWing.PutOn:
                {
                    ModelProxy.change("wing", "puton", param1.getParam());
                    break;
                }
                case CMDWing.RandomIntel:
                {
                    ModelProxy.change("wing", "random", param1.getParam());
                    break;
                }
                case CMDWing.Uplevel:
                {
                    ModelProxy.change("wing", "uplevel", param1.getParam());
                    _loc_2 = param1.getParam();
                    _loc_3 = ModelProxy.getValue("data", "jingjitypedata");
                    if (_loc_3 != null)
                    {
                        if (_loc_3[4])
                        {
                            _loc_6 = false;
                            _loc_7 = ConfigDictionary.data.activitygoal;
                            _loc_8 = _loc_2[0];
                            _loc_9 = _loc_8.level;
                            for each (_loc_11 in _loc_7[4])
                            {
                                
                                _loc_10 = _loc_10 + 1;
                                if (_loc_3[4][0][(_loc_10 - 1)].isGet == 0 && _loc_9 >= _loc_11.goal && _loc_3[4][0][(_loc_10 - 1)].count < _loc_11.count)
                                {
                                    _loc_6 = true;
                                    ModelProxy.change("mainui", "showEffect", {ab:"kaifujingji", state:_loc_6});
                                    break;
                                }
                            }
                        }
                    }
                    _loc_4 = ModelProxy.getValue("data", "wing");
                    _loc_5 = _loc_4[0].level;
                    ModelProxy.change("data", "wing", param1.getParam());
                    if (_loc_5 != _loc_2[0].level)
                    {
                        _loc_12 = ModelProxy.getValue("data", "jingjitypedata")[28];
                        _loc_13 = false;
                        _loc_14 = _loc_2[0].level;
                        if (_loc_12)
                        {
                            for each (_loc_15 in _loc_12[0])
                            {
                                
                                if (_loc_15.goal == _loc_14)
                                {
                                    if (_loc_15.isGet == 0)
                                    {
                                        _loc_13 = true;
                                        break;
                                    }
                                }
                            }
                            ModelProxy.change("mainui", "updateHuoDongEffect", {name:"baifu", page:"guangyishengyan", state:_loc_13});
                            ModelProxy.change("specialActivity", "updateTitleAngle", {type:5, page:"guangyishengyan", state:_loc_13});
                        }
                        ModelProxy.change("specialActivity", "updateStateChange", null);
                    }
                    ModelProxy.change("data", "newwing", 0);
                    ModelProxy.change("data", "wingLuck", _loc_2[0].luck);
                    ModelProxy.change("mainview", "showWingCount", null);
                    break;
                }
                case CMDWing.NewHorse:
                {
                    ModelProxy.change("wing", "newHorse", param1.getParam());
                    ModelProxy.change("tasktrack", "init", UserData.getData(UserDataType.Task));
                    ModelProxy.change("data", "newwing", 1);
                    ModelProxy.change("mainview", "showWingCount", null);
                    break;
                }
                case CMDWing.SkillUp:
                {
                    ModelProxy.change("wing", "upskilllevel", param1.getParam());
                    break;
                }
                case Error:
                {
                    ModelProxy.change("movetips", "error", param1.getParam());
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealBufferMessage(param1:IBufferMessage) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Input = null;
            var _loc_4:ByteArray = null;
            switch(param1.getCmd())
            {
                case 6:
                {
                    _loc_2 = new Object();
                    _loc_3 = new Input(null);
                    _loc_4 = param1.getBody();
                    _loc_4.position = 0;
                    _loc_3.setBytes(_loc_4);
                    _loc_2.num = _loc_3.readVarInt(false);
                    ModelProxy.change("wing", "addjuexing", _loc_2);
                    ModelProxy.change("data", "wingJueXing", _loc_2.num);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealProxyMessage(param1:IProxyMessage) : void
        {
            return;
        }// end function

    }
}
